﻿/*
 * Logging mechanism for debugging.
 * Restrain from using own debug logs to avoid chaos.
 */

#if DEBUG

using System;
using System.Diagnostics;

namespace ZOIL.Framework.Core
{
    /// <summary>
    /// 
    /// </summary>
    [Flags]
	public enum DebugCategories
	{
        /// <summary>
        /// 
        /// </summary>
        None = 0,
		
        /// <summary>
        /// 
        /// </summary>
        Core = 1,
		
        /// <summary>
        /// 
        /// </summary>
        InformationLandscape = 2,
		
        /// <summary>
        /// 
        /// </summary>
        Animations = 4,
		
        /// <summary>
        /// 
        /// </summary>
        Input = 8,
		
        /// <summary>
        /// 
        /// </summary>
        Components = 16,
		
        /// <summary>
        /// 
        /// </summary>
        Visualizations = 32,
		
        /// <summary>
        /// 
        /// </summary>
        Demo = 64
	}

    /// <summary>
    /// 
    /// </summary>
	public enum DebugLevel
	{
        /// <summary>
        /// 
        /// </summary>
        None = 0,
		
        /// <summary>
        /// 
        /// </summary>
        Error = 1,
		
        /// <summary>
        /// 
        /// </summary>
        Warning = 2,
		
        /// <summary>
        /// 
        /// </summary>
        Message = 3,
		
        /// <summary>
        /// 
        /// </summary>
        Info = 4,
		
        /// <summary>
        /// 
        /// </summary>
        Spam = 5
	}

    /// <summary>
    /// 
    /// </summary>
	public static class ZDebug
	{
		/// <summary>
		/// Subscribe to a debug category.
		/// </summary>
		/// <param name="category">Debug category.</param>
		public static void Register(DebugCategories category)
		{
			ZConfig.DebugCategories |= (int)category;
		}

		/// <summary>
		/// Adds a message to the debug log.
		/// </summary>
		/// <param name="level">Debug level.</param>
		/// <param name="category">Debug category.</param>
		/// <param name="message">Debug message (newline is appended).</param>
		public static void Log(DebugLevel level, DebugCategories category, String message)
		{
			Trace.WriteLineIf((int)level <= (int)ZConfig.DebugLevel && (((int)category & ZConfig.DebugCategories) != 0), String.Format("{0}: {1}", category, message));
		}

		/// <summary>
		/// Adds a quick message to the debug log, without specifying the debug category and level
		/// </summary>
		/// <param name="message"></param>
		public static void QuickLog(Object message)
		{
			Trace.WriteLine(String.Format("QuickLog: {0}", message));
		}
	}
}

#endif